class MusicPlayer {
  constructor() {
    this.musicList = [];
    this.currentPlayingMusic = null;
    this.playMode = "repeat";
  }

  addMusic(music) {
    this.musicList.push(music);
  }

  deleteMusic(music) {
    const index = this.musicList.indexOf(music);
    if (index !== -1) {
      this.musicList.splice(index, 1);
    }
  }

  playMusic() {
    if (this.musicList.length === 0) {
      console.log("No music in the list");
      return;
    }

    if (!this.currentPlayingMusic) {
      this.currentPlayingMusic = this.musicList[0];
      console.log("Now playing:", this.currentPlayingMusic);
    } else {
      const index = this.musicList.indexOf(this.currentPlayingMusic);
      if (index === -1) {
        console.log("The current playing music is not in the list");
        return;
      }

      if (index === this.musicList.length - 1) {
        if (this.playMode === "repeat") {
          this.currentPlayingMusic = this.musicList[0];
        } else {
          console.log("No more music to play");
          return;
        }
      } else {
        this.currentPlayingMusic = this.musicList[index + 1];
      }

      console.log("Now playing:", this.currentPlayingMusic);
    }
  }
}